package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//创建配置类确保连接器能生效
@Configuration  //
@ConditionalOnClass(DispatcherServlet.class)   //条件限制对于spring内部的启动类生效
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建用户信息连接器的对象
        registry.addInterceptor(new UserInfoInterceptor());
    }
}
